package org.amr.arabic;

/*
 *	Date : 8th of June 2009
 *	the class is Arabic string reshaper Utilities, this class is targeting Android platform
 *
 * 	By		: Amr Ismail Gawish
 *  E-Mail 	: amr.gawish@gmail.com
 *  Web		: http://www.amr-gawish.com
 *  
 *  Updated : 8th of June 2009
 *  Adding comments and Announcing Open Source
 *  
 * Updated: 6th of May 2010
 * Enahancing Functionality by Amine : bakhtout@gmail.com
 *
 * */

/**
 * This class is the main class that is responsible for Reshaping Arabic Sentences and Text
 * Utilities Class to make it easier to deal with Arabic Reshaper Class
 * Wrapper for Arabic Reshaper Class
 * @author Amr Gawish
 */
public class ArabicUtilities
{
	/**
	 * Helper function to split Sentence By Space
	 * @param sentence the Sentence to Split into Array of Words
	 * @return Array Of words
	 */
	private static String[] getWords(String sentence){
		if (sentence != null) {
			return sentence.split("\\s");
		} else {
			return new String[0];
		}
	}

	/**
	 * The Main Reshaping Function to be Used in Android Program
	 * @param allText The text to be Reshaped
	 * @return the Reshaped Text
	 */
	public static String reshapeSentence(String sentence)
	{
		//get the Words from the Text
		String[] words=getWords(sentence);
		//prepare the Reshaped Text
		StringBuffer reshapedText=new StringBuffer("");
		//Iterate over the Words
		for(int i=0;i<words.length;i++){
			//Initiate the ArabicReshaper functionality
			ArabicReshaper arabicReshaper=new ArabicReshaper(words[i]);
			//Append the Reshaped Arabic Word to the Reshaped Whole Text
			reshapedText.append(arabicReshaper.getReshapedWord());
			//Append the space to separate between words
			reshapedText.append(" ");
		}
		//return the final reshaped whole text
		return reshapedText.toString();
	}
}
